<!DOCTYPE html>
<html>

	<head lang="en">
		<title>骡窝日报</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/plugins/jquery/jquery.min.js"></script>
		<script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/news.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
		<script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
		<script src="/js/common.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.js"></script>


        <script>
            $(function(){


                //当前页input设置的值,不代表最终值    这里是获取到1
                var currentPage = $("#currentPage");

                //用于存储游记列表的数据
                //重复渲染数据时,把前面的数据一起渲染,防止数据丢失
                var travelData = []

                //游记总页数
                var pages = 1;

                function query() {


                    //找到页码id,这才是值
                    var currentPageValue = currentPage.val()
                    //每页显示数量
                    var pageSize = $("#pageSize").val()

                    //异步请求,获取游记列表      {}发送到controller的参数
                    $.get('/news',{currentPage:currentPageValue,pageSize:pageSize},function (data) {
                        //往数组中存储数据(合并数据)
                        //把异步请求弄来的第二组数据的内容,合并到第一个数据中
                        //data相当于PageInfo对象,从中提取list
                        //list 通过controller查询出来的数据库的数据结果合集   从data中获取
                        //console.log(data);
                        $.merge(travelData,data.list)


                        //每次渲染,都会清空上一次渲染出来的数据
                        //所以每次滚动,都会清空前面的数据
                        $(".row").renderValues({list:travelData})

                        //设置当前页+1
                        //parseInt  转成数字再运算+1
                        //确保获取到第二页数据再+1
                        currentPage.val(parseInt(currentPageValue) + 1);


                        //设置总页数的值
                        pages = data.pages

                        //给a链接绑定事件
                        //渲染之后,再绑定
                        $("a[data-url]").click(function () {
                            var url= $(this).data("url")

                            console.log($(this).data("url"));
                            var id = $(this).data("id")
                            window.location.href = url + id

                        })
                        $("a[data-urll]").click(function () {
                            var url= $(this).data("url")

                            console.log($(this).data("url"));
                            var id = $(this).data("id")
                            window.location.href = url + id

                        })


                    })

                }

                //默认查询第一页数据,以防打开网页时不显示
                query();


                //滚动事件
                $(window).scroll(function () {
                    //document(html)卷上去的高度 + 窗口高度 >= document整个高度,要分页的依据
                    // 把对象封装成jquery的对象
                    //jquery的对象,要用()包起来
                    console.log($(document).scrollTop() + $(window).height());
                    console.log($(document).height());
                    if($(document).scrollTop()+$(window).height()>=($(document).height()-9)){


                        //判断currentPageValue当前页是否大于pages总页数
                        var currentPageValue = currentPage.val()

                        if(currentPageValue <= pages){
                            query()
                        }else{
                            //提示用户已经到底了
                            $(document).dialog({
                                type: 'notice',
                                infoText: '已经到底了',
                                autoClose: 2500
                            })
                        }
                    }
                })
            })

		</script>

	</head>


	<body>


	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search">
					<input class="form-control searchBtn" placeholder="搜索资讯">
				</div>
			</div>
		</div>
	</div>

	<input type="hidden" name="currentPage" id="currentPage" value="1" >
	<input type="hidden" name="pageSize" id="pageSize" value="3" >

	<div class="container news">

		<div class="news">
			<h6 class="news-title">骡窝日报 </h6>
			<div class="row">
				<dl class="list" render-loop="list">
					<dd>
						<div>
						<a href="javascript:;"
						   data-url="/newsContent.html?id=" render-attr="data-id=list.id">
							<img render-src="list.coverUrl" width="300px%" height="110px"  />
							<h6 class="title" render-html="list.title"></h6>

						</a>
						</div>

						<div>
							<p>发布时间 <span render-html="list.releaseTime"></span>
								<a href="javascript:;"
								data-urll="/xx.html?id=" render-attr="data-id=list.id">
								<i class="fa fa-heart-o">

								</i>
								</a>
								</span>窝窝官方</span>
							</p>
						</div>

					</dd>

				</dl>

			</div>

		</div>
	</div>



	</body>
</html>

